|
1
|
|
|
/** global: appSettings */ |
|
2
|
|
|
var whois = require('../../common/whoiswrapper.js'), |
|
3
|
|
|
conversions = require('../../common/conversions.js'), |
|
4
|
|
|
fs = require('fs'), |
|
5
|
|
|
bwaFileContents; |
|
6
|
|
|
|
|
7
|
|
|
|
|
8
|
|
|
require('../../common/stringformat.js'); |
|
9
|
|
|
|
|
10
|
|
|
const { |
|
11
|
|
|
ipcRenderer |
|
12
|
|
|
} = require('electron'); |
|
13
|
|
|
|
|
14
|
|
|
// File input, path and information confirmation container |
|
15
|
|
|
ipcRenderer.on('bwa:fileinput.confirmation', function(event, filePath = null, isDragDrop = false) { |
|
16
|
|
|
const { |
|
17
|
|
|
misc, |
|
18
|
|
|
lookup |
|
19
|
|
|
} = appSettings; |
|
20
|
|
|
var bwaFileStats; // File stats, size, last changed, etc |
|
21
|
|
|
|
|
22
|
|
|
//console.log(filePath); |
|
23
|
|
|
if (filePath === undefined || filePath == '' || filePath === null) { |
|
24
|
|
|
//console.log(filePath); |
|
25
|
|
|
$('#bwaFileinputloading').addClass('is-hidden'); |
|
26
|
|
|
$('#bwaEntry').removeClass('is-hidden'); |
|
27
|
|
|
} else { |
|
28
|
|
|
|
|
29
|
|
|
$('#bwaFileSpanInfo').text('Loading file stats...'); |
|
30
|
|
|
if (isDragDrop === true) { |
|
31
|
|
|
$('#bwaEntry').addClass('is-hidden'); |
|
32
|
|
|
$('#bwaFileinputloading').removeClass('is-hidden'); |
|
33
|
|
|
bwaFileStats = fs.statSync(filePath); |
|
34
|
|
|
bwaFileStats['filename'] = filePath.replace(/^.*[\\\/]/, ''); |
|
35
|
|
|
bwaFileStats['humansize'] = conversions.byteToHumanFileSize(bwaFileStats['size'], misc.usestandardsize); |
|
36
|
|
|
$('#bwaFileSpanInfo').text('Loading file contents...'); |
|
37
|
|
|
bwaFileContents = fs.readFileSync(filePath); |
|
38
|
|
|
} else { |
|
39
|
|
|
bwaFileStats = fs.statSync(filePath[0]); |
|
40
|
|
|
bwaFileStats['filename'] = filePath[0].replace(/^.*[\\\/]/, ''); |
|
41
|
|
|
bwaFileStats['humansize'] = conversions.byteToHumanFileSize(bwaFileStats['size'], misc.usestandardsize); |
|
42
|
|
|
$('#bwaFileSpanInfo').text('Loading file contents...'); |
|
43
|
|
|
bwaFileContents = fs.readFileSync(filePath[0]); |
|
44
|
|
|
} |
|
45
|
|
|
$('#bwaFileSpanInfo').text('Getting line count...'); |
|
46
|
|
|
bwaFileStats['linecount'] = bwaFileContents.toString().split('\n').length; |
|
47
|
|
|
bwaFileStats['filepreview'] = bwaFileContents.toString().substring(0, 50); |
|
48
|
|
|
|
|
49
|
|
|
//console.log(readLines(filePath[0])); |
|
50
|
|
|
//console.log(bwFileStats['filepreview']); |
|
51
|
|
|
|
|
52
|
|
|
//console.log(lineCount(bwFileContents)); |
|
53
|
|
|
$('#bwaFileinputloading').addClass('is-hidden'); |
|
54
|
|
|
$('#bwaFileinputconfirm').removeClass('is-hidden'); |
|
55
|
|
|
|
|
56
|
|
|
// stats |
|
57
|
|
|
$('#bwaFileTdFilename').text(bwaFileStats['filename']); |
|
58
|
|
|
$('#bwaFileTdLastmodified').text(conversions.getDate(bwaFileStats['mtime'])); |
|
59
|
|
|
$('#bwaFileTdLastaccessed').text(conversions.getDate(bwaFileStats['atime'])); |
|
60
|
|
|
$('#bwaFileTdFilesize').text(bwaFileStats['humansize'] + ' ({0} line(s))'.format(bwaFileStats['linecount'])); |
|
61
|
|
|
$('#bwaFileTdFilepreview').text(bwaFileStats['filepreview'] + '...'); |
|
62
|
|
|
//$('#bwTableMaxEstimate').text(bwFileStats['maxestimate']); |
|
63
|
|
|
//console.log('cont:'+ bwFileContents); |
|
64
|
|
|
|
|
65
|
|
|
//console.log(bwFileStats['linecount']); |
|
66
|
|
|
} |
|
67
|
|
|
}); |
|
68
|
|
|
|
|
69
|
|
|
// File Input, Entry container button |
|
70
|
|
|
$('#bwaEntryButtonOpen').click(function() { |
|
71
|
|
|
$('#bwaEntry').addClass('is-hidden'); |
|
72
|
|
|
$.when($('#bwaFileinputloading').removeClass('is-hidden').delay(10)).done(function() { |
|
73
|
|
|
ipcRenderer.send("bwa:input.file"); |
|
74
|
|
|
}); |
|
75
|
|
|
}); |
|
76
|
|
|
|
|
77
|
|
|
|
|
78
|
|
|
// File Input, cancel file confirmation |
|
79
|
|
|
$('#bwaFileinputconfirmButtonCancel').click(function() { |
|
80
|
|
|
$('#bwaFileinputconfirm').addClass('is-hidden'); |
|
81
|
|
|
$('#bwaEntry').removeClass('is-hidden'); |
|
82
|
|
|
}); |
|
83
|
|
|
/* |
|
84
|
|
|
// File Input, proceed to bulk whois |
|
85
|
|
|
$('#bwafButtonConfirm').click(function() { |
|
86
|
|
|
var bwDomainArray = bwFileContents.toString().split('\n').map(Function.prototype.call, String.prototype.trim); |
|
87
|
|
|
var bwTldsArray = $('#bwfSearchTlds').val().toString().split(','); |
|
88
|
|
|
|
|
89
|
|
|
$('#bwFileInputConfirm').addClass('is-hidden'); |
|
90
|
|
|
$('#bwProcessing').removeClass('is-hidden'); |
|
91
|
|
|
|
|
92
|
|
|
ipcRenderer.send("bulkwhois:lookup", bwDomainArray, bwTldsArray); |
|
93
|
|
|
}); |
|
94
|
|
|
|
|
95
|
|
|
// Bulk whois file input by drag and drop |
|
96
|
|
|
(function() { |
|
97
|
|
|
var holder = document.getElementById('bwaMainContainer'); |
|
98
|
|
|
holder.ondragover = function() { |
|
99
|
|
|
return false; |
|
100
|
|
|
}; |
|
101
|
|
|
|
|
102
|
|
|
holder.ondragleave = function() { |
|
103
|
|
|
return false; |
|
104
|
|
|
}; |
|
105
|
|
|
|
|
106
|
|
|
holder.ondragend = function() { |
|
107
|
|
|
return false; |
|
108
|
|
|
}; |
|
109
|
|
|
|
|
110
|
|
|
holder.ondrop = function(event) { |
|
111
|
|
|
event.preventDefault(); |
|
112
|
|
|
for (let f of event.dataTransfer.files) { |
|
113
|
|
|
ipcRenderer.send('File(s) you dragged here: {0}'.format(f.path)); |
|
114
|
|
|
ipcRenderer.send('ondragstart', f.path); |
|
115
|
|
|
} |
|
116
|
|
|
return false; |
|
117
|
|
|
}; |
|
118
|
|
|
})(); |
|
119
|
|
|
|
|
120
|
|
|
// Enter when confirming file input bulk whois |
|
121
|
|
|
document.getElementById('bwfSearchTlds').addEventListener("keyup", function(event) { |
|
122
|
|
|
// Cancel the default action, if needed |
|
123
|
|
|
event.preventDefault(); |
|
124
|
|
|
// Number 13 is the "Enter" key on the keyboard |
|
125
|
|
|
if (event.keyCode === 13) { |
|
126
|
|
|
// Trigger the button element with a click |
|
127
|
|
|
$('#bwfButtonConfirm').click(); |
|
128
|
|
|
} |
|
129
|
|
|
}); |
|
130
|
|
|
*/ |
|
131
|
|
|
|